package com.github.binarywang.demo.wechat.controller;

import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author hhx
 */
@RestController
public class JssdkController {

    @Autowired
    WxMpService wxService;

    /**
     * 通过config接口注入权限验证配置,获取签名信息
     * @param url
     * @return
     */
    @PostMapping("/jssdk/getSignature")
    public WxJsapiSignature getSignature(@RequestParam(name="url")String url){
        WxJsapiSignature createJsapiSignature = null;
        try {
            createJsapiSignature = wxService.createJsapiSignature(url);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("error");
        }
        return createJsapiSignature;
    }
}
